//
//  RaeRequestApi.swift
//  77Club
//
//  Created by Apple on 2024/8/26.
//

import Foundation
import Alamofire

enum RaeRequestApi {

    case login(user_name: String, passwd: String, t: String, sign: String)
    case sendCode(phone: String, type: String)
    //邮箱验证码
    case sendEmailCode(email: String)
    //修改密码
    case editPassword(json: [String: Any])
    //扫码登录
    case scanLogin(token: String)
    case phoneNumLogin(phone: String, sessionid: String, code: String, passwd: String, invite: String)
    case register(user_name: String, passwd: String, t: String, sign: String, invite: String)
    case homeConfig
    case home(type: String, gameType: String, page: Int)
    case homeRecommend(page: Int)
    //是否存在新消息
    case newMessage
    //消息列表
    case messageList(page: Int)
    //标记为已读
    case readAllList(id: String)
    //删除消息
    case delMessge(id: String)
    case gameClassify
    case gameList(gameType: String, page: Int)
    case infoCate
    case infolist(class_id: String, page: Int, keyword: String)
    case commitList(gameId: String, page: Int, sortby: String)
    case homeWuKong(gid: String, page: Int)
    case dynamicList(page: Int)
    case dynamicLike(type: String, dynamicID: String)
    case dynamicTopic(keyword: String)
    case dynamicGame(keyword: String)
    case dynamicDetail(is_look: String, dynamicID: String)
    case dynamicCommitList(dynamicID: String, page: Int)
    case dynamicCommit(dynamicID: String, pid: String, content: String)
    //上传文件
    case upload
    //发布动态
    case pushDynamic
    //游戏详情标签列表
    case gameTagList(gameID: String)
    //游戏详情顶部数据
    case gameDetailTop(gameID: String)
    //游戏详情
    case gameDetailInfo(gameID: String)
    //获取子评论
    case getSonCommitList(pid: String)
    //个人中心
    case mineInfo(uid: String)
    //社区列表
    case communityList(page: Int, type: String, keyword: String, uid: String, is_bbs: String)
    //关注的社区
    case followCommunityList(uid: String)
    //社区关注
    case communityFollow(communityID: String)
    //社区顶部信息
    case communityTop(communityID: String)
    //社区帖子list sortby 0=时间 1=热度
    case communityPostList(communityID: String, type: String, sortby: String, page: Int, _ keyword: String = "")
    //游戏社区攻略
    case strategyInfo(communityID: String, page: Int)
    //社区文章详情
    case strategyPostInfo(newID: String)
    //社区文章详情评论列表
    case strategyPostCommitList(newID: String, uid: String, sortby: String)
    //社区文章、评论点赞 type 0 对文章点赞  1 对评论点赞
    case likeStrategyPost(pid: String,puid: String,type: String)
    //社区文章评论 type 1=子评论 0=评论
    case addStrategyCommit(pid: String, puid: String, type: String, content: String, news_id: String)
    //积分商城
    case mallList(page: Int)
    //积分商城详情
    case mallDetail(goodsId: String)
    //商品收藏 type:0游戏  1积分商城  2交易
    case collectGoods(goodsId: String, type: String)
    //取消收藏 type:0游戏  1积分商城  2交易
    case cancelCollectGoods(goodsId: String, type: String)
    //每日签到info
    case dailyInfo
    //每日签到
    case dailyCheck
    //搜索_热门搜索
    case hotSearch
    //搜索_关键词搜索
    case searchGames(keyString: String, is_bbs: Int)
    //开服列表
    case openService(gameId: String)
    //我的兑换
    case myExchangeList(page: Int)
    //我的收藏 type 0: 游戏 1: 商品
    case myCollectList(type: String, page: Int)
    //我的评论
    case myCommitList
    //删除我的评论
    case delMyCommit(commitID: String)
    //个人主页
    case getUserInfo
    //发布文章
    case pushCommunityPost(json: [String: Any])
    //修改个人资料
    case updateUserInfo(value: String)
    //发表游戏评论
    case commitGame(json: [String: Any])
    //实名认证
    case realVerfity(value: String)
    //重置密码
    case resetPassword(json: [String: Any])
    //我的地址列表
    case myAddressList
    //添加地址
    case addAddress(value: String)
    //删除地址
    case delAddress(addressID: String)
    //安全中心
    case safeCenter
    //我的资产
    case myAssets
    //我的礼包
    case myGiftList(page: Int)
    //资讯点赞
    case likeInfo(infoID: String)
    //游戏评论点赞
    case likeGameCommit(commitID: String)
    //弹窗
    case homeAlert
    //获取启动图
    case getLaunchScreen
    //举报
    case report(id: String, remark: String, type: String)
    //删除动态
    case delDynamic(id: String)
    //添加预约
    case addAppointment(gid: String)
    //别人主页动态列表
    case otherDynamicList(uid: String, page: Int)
    //加入黑名单
    case addBlackList(uid: String)
    //删除黑名单
    case delBlackList(uid: String)
    //黑名单列表
    case blackList(page: Int)
    //活动列表
    case activeList(gid: String)
    //app版本更新
    case appUpdate(codeVersion: String)
    //删除评论
    case delCommit(commitID: String)
    //删除文章
    case delPost(postID: String)
    //删除动态评论
    case delDynamicCommit(commitID: String)
    //删除社区评论
    case delForumCommit(commitID: String)
    //临时举报接口
    case shequReport(id: String, remark: String, type: String)
    //广场-话题列表
    case squareTopicList(page: Int, topicID: String)
    //修改论坛信息
    case editSquareInfo(gid: String, field: String, value: String)
    //论坛成员列表 当role=1时，查询管理员列表
    case squareMemberList(gid: String, role: String, keyword: String, page: Int)
    //禁言成员列表
    case squareBanMember(gid: String, page: Int)
    //论坛用户禁言
    case forumMemberBan(gid: String, user_id: String)
    //论坛取消禁言
    case forumMemberCancelBan(gid: String, user_id: String)
    //论坛增加管理员
    case forumAddAdmin(gid: String, user_id: String)
    //论坛取消管理员
    case forumCancelAdmin(gid: String, user_id: String)
    //关注设置 system_type 1=真实,2=虚拟
    case forumFollowSetting(gid: String, system_type: String, guanzhu_num: String, settings: String)
    //获取单个管理员权限
    case adminPerm(gid: String, user_id: String)
    //编辑管理员权限 perm_ban,perm_top,perm_off,perm_notice,perm_guanzhu(只能是1或0)
    case editAdminPerm(gid: String, user_id: String, field: String, value: String)
    //搜索帖子
    case searchPost(keyword: String)
    //帖子下架/上架
    case postUpOrDown(id: String)
    //帖子置顶/取消置顶
    case postTopOrDown(id: String)
    //搜索动态
    case searchDynamic(keyword: String)
    //收藏论坛
    case collectForum(newsId: String)
    //我发的帖子
    case myForumList(page: Int)
    //其他人发的帖子
    case otherForumList(userId: String, page: Int)
}

extension RaeRequestApi {
    
    /// 请求路径
    /// Request Path
    var path: String {
        switch self {
        case .login:                       return "ct=app&ac=login&ios=1"
        case .sendCode:                    return "ct=app&ac=mobile_code&ios=1"
        case .sendEmailCode:               return "ct=app&ac=email_code&ios=1&type=1"
        case .phoneNumLogin:               return "ct=app&ac=phone_login&ios=1"
        case .register:                    return "ct=app&ac=username_reg&ios=1"
        case .editPassword:                return "ct=app&ac=re_passwd&ios=1"
        case .homeConfig:                  return "ct=app2023&ac=index_config"
        case .home:                        return "ct=app2023"
        case .homeRecommend:               return "ct=gamenav&ac=home"
        case .newMessage:                  return "ct=app&ac=new_message&ios=1&Version=3.0"
        case .messageList:                 return "ct=app&ac=message&ios=1&Version=3.0"
        case .readAllList:                 return "ct=app&ac=message_read&ios=1&Version=3.0"
        case .delMessge:                   return "ct=app&ac=message_del&ios=1&Version=3.0"
        case .gameClassify:                return "ct=app&ac=fenlei"
        case .gameList:                    return "ct=app&ac=fenlei_game"
        case .infoCate:                    return "ct=news&ac=classs"
        case .infolist:                    return "ct=news"
        case .commitList:                  return "ct=app2021&ac=gameinfo_pllist"
        case .homeWuKong:                  return "ct=gamenav&ac=index"
        case .dynamicList:                 return "ct=dongtai"
        case .dynamicLike:                 return "ct=dongtai&ac=zan"
        case .dynamicTopic:                return "ct=gamenav&ac=sesubject"
        case .dynamicGame:                 return "ct=gamenav&ac=segame"
        case .dynamicDetail:               return "ct=dongtai&ac=info"
        case .dynamicCommitList:           return "ct=dongtai&ac=pinglun"
        case .dynamicCommit:               return "ct=dongtai&ac=pinglun_add"
        case .upload:                      return "ct=app&ac=upload"
        case .pushDynamic:                 return "ct=dongtai&ac=add"
        case .gameTagList:                 return "ct=shequ&ac=game_biaoqian"
        case .gameDetailTop:               return "ct=app2021&ac=gameinfo_top"
        case .gameDetailInfo:              return "ct=app2021&ac=gameinfo_content&model=ios"
        case .getSonCommitList:            return "ct=app2021&ac=gameinfo_pllistson"
        case .mineInfo:                    return "ct=app2022&ac=account"
        case .communityList:               return "ct=shequ&ac=lists"
        case .communityFollow:             return "ct=shequ&ac=guanzhu"
        case .communityTop:                return "ct=shequ&ac=index"
        case .communityPostList:           return "ct=shequ&ac=news&ios=1"
        case .strategyInfo:                return "ct=shequ&ac=news&type=3"
        case .strategyPostInfo:            return "ct=shequ&ac=news_info"
        case .strategyPostCommitList:      return "ct=shequ&ac=pinglun"
        case .likeStrategyPost:            return "ct=shequ&ac=good"
        case .mallList:                    return "ct=app&ac=mall"
        case .mallDetail:                  return "ct=app&ac=mall_info"
        case .collectGoods:                return "ct=app&ac=shoucang_add"
        case .cancelCollectGoods:          return "ct=app&ac=shoucang_del"
        case .dailyInfo:                   return "ct=app&ac=my_sign"
        case .dailyCheck:                  return "ct=app&ac=sign"
        case .hotSearch:                   return "ct=app&ac=hot_so"
        case .searchGames:                 return "ct=app&ac=search_info"
        case .openService:                 return "ct=app&ac=game_info2"
        case .addStrategyCommit:           return "ct=shequ&ac=pinglun_add"
        case .myExchangeList:              return "ct=app&ac=mall_order"
        case .myCollectList:               return "ct=app&ac=mycollect"
        case .myCommitList:                return "ct=app&ac=mypinglun"
        case .delMyCommit:                 return "ct=app&ac=mypinglun_del"
        case .getUserInfo:                 return "ct=app&ac=account_info"
        case .pushCommunityPost:           return "ct=shequ&ac=add"
        case .updateUserInfo:              return "ct=app&ac=re_info"
        case .commitGame:                  return "ct=app2021&ac=gameinfo_pinglun"
        case .realVerfity:                 return "ct=app&ac=re_info"
        case .myAddressList:               return "ct=app&ac=my_address"
        case .delAddress:                  return "ct=app&ac=address_del"
        case .addAddress:                  return "ct=app&ac=address_add"
        case .safeCenter:                  return "ct=app&ac=anquan"
        case .myAssets:                    return "ct=app&ac=myassets&Version=3.0"
        case .myGiftList:                  return "ct=app&ac=mylb"
        case .resetPassword:               return "ct=app&ac=edit_passwd"
        case .scanLogin:                   return "ct=app2022&ac=saoyisao"
        case .likeInfo:                    return "ct=news&ac=zan&type=0"
        case .likeGameCommit:              return "ct=app2021&ac=pinglun_zan"
        case .homeAlert:                   return "ct=app&ac=pop"
        case .getLaunchScreen:             return "ct=app&ac=welcome"
        case .report:                      return "ct=gamenav&ac=report&os=4"
        case .delDynamic:                  return "ct=dongtai&ac=del"
        case .addAppointment:              return "ct=app&ac=yuyue_add"
        case .followCommunityList:         return "ct=shequ&ac=guanzhu_list"
        case .otherDynamicList:            return "ct=dongtai&ac=index2"
        case .addBlackList:                return "ct=app2022&ac=blacklist_add"
        case .delBlackList:                return "ct=app2022&ac=blacklist_del"
        case .blackList:                   return "ct=app2022&ac=blacklist"
        case .activeList:                  return "ct=app&ac=huodong"
        case .appUpdate:                   return "ct=app&ac=isupdate"
        case .delCommit:                   return "ct=app2021&ac=dell_pinglun"
        case .delPost:                     return "ct=shequ&ac=del"
        case .delDynamicCommit:            return "ct=dongtai&ac=pinglun_del"
        case .delForumCommit:              return "ct=shequ&ac=pinglun_del"
        case .shequReport:                 return "ct=shequ&ac=report"
        case .squareTopicList:             return "ct=gamenav&ac=subjects"
        case .editSquareInfo:              return "ct=shequ&ac=bbs_edit"
        case .squareMemberList:            return "ct=shequ&ac=users"
        case .squareBanMember:             return "ct=shequ&ac=bans"
        case .forumMemberBan:              return "ct=shequ&ac=user_ban"
        case .forumMemberCancelBan:        return "ct=shequ&ac=cancel_ban"
        case .forumAddAdmin:               return "ct=shequ&ac=add_admin"
        case .forumCancelAdmin:            return "ct=shequ&ac=cancel_admin"
        case .forumFollowSetting:          return "ct=shequ&ac=guanzhu_edit"
        case .adminPerm:                   return "ct=shequ&ac=get_admin_perm"
        case .editAdminPerm:               return "ct=shequ&ac=admin_perm_edit"
        case .searchPost:                  return "ct=gamenav&ac=sebbs"
        case .postUpOrDown:                return "ct=shequ&ac=news_off"
        case .postTopOrDown:               return "ct=shequ&ac=news_best"
        case .searchDynamic:               return "ct=dongtai"
        case .collectForum:                return "ct=news&ac=shoucang&type=1"
        case .myForumList:                 return "ct=shequ&ac=my"
        case .otherForumList:              return "ct=shequ&ac=news"
        }
    }
    
    /// 参数拼接
    /// Splicing Parameters
    var parameters: [String : Any] {
        var para:[String : Any] = [String : Any]()
        switch self {
        case .searchGames(let keyword, let is_bbs):
            para["keyword"] = keyword
            para["is_bbs"] = is_bbs
        case .openService(let gameId):
            para["id"] = gameId
        case .pushCommunityPost(let json): para.merge(json, uniquingKeysWith: {$1})
        case .updateUserInfo(let value):
            para["value"] = value
        case .commitGame(let json): para.merge(json, uniquingKeysWith: {$1})
        case .realVerfity(let value):
            para["value"] = value
        case .addAddress(let value):
            para["value"] = value
        case .delAddress(let addressID):
            para["id"] = addressID
        case .editPassword(let json): para.merge(json, uniquingKeysWith: {$1})
        case .resetPassword(let json): para.merge(json, uniquingKeysWith: {$1})
        case .scanLogin(let token):
            para["token"] = token
        case .report(let dynamicID, let remark, let type):
            para["id"] = dynamicID
            para["remark"] = remark
            para["type"] = type
        case .dynamicCommit(let dynamicID, let pid, let content):
            para["dongtai_id"] = dynamicID
            para["pid"] = pid
            para["content"] = content
        case .addStrategyCommit(let pid, let puid, let type, let content, let news_id):
            para["pid"] = pid
            para["puid"] = puid
            para["type"] = type
            para["content"] = content
            para["news_id"] = news_id
        case .infolist(let class_id, let page, let keyword):
            para["class_id"] = class_id
            para["page"] = page
            para["keyword"] = keyword
        case .dynamicGame(let keyword):
            para["keyword"] = keyword
        case .dynamicTopic(let keyword):
            para["keyword"] = keyword
        case .shequReport(let dynamicID, let remark, let type):
            para["id"] = dynamicID
            para["remark"] = remark
            para["type"] = type
        case .editSquareInfo(let gid, let field, let value):
            para["gid"] = gid
            para["field"] = field
            para["value"] = value
        case .forumFollowSetting(let gid, let system_type, let guanzhu_num, let settings):
            para["gid"] = gid
            para["system_type"] = system_type
            para["guanzhu_num"] = guanzhu_num
            para["settings"] = settings
        case .editAdminPerm(let gid, let user_id, let field, let value):
            para["gid"] = gid
            para["user_id"] = user_id
            para["field"] = field
            para["value"] = value
        case .searchPost(let keyword):
            para["keyword"] = keyword
        case .communityPostList(let communityID, let type,let sortby, let page, let keyword):
            para["id"] = communityID
            para["type"] = type
            para["sortby"] = sortby
            para["p"] = page
            para["keyword"] = keyword
        case .squareMemberList(let gid, let role, let keyword, let page):
            para["gid"] = gid
            para["role"] = role
            para["keyword"] = keyword
            para["p"] = page
        case .searchDynamic(let keyword):
            para["keyword"] = keyword
        case .collectForum(let newsId):
            para["news_id"] = newsId

//        case .addStrategyCommit(let pid, let puid, let type, let content):
//            para["pid"] = pid
//            para["puid"] = puid
//            para["type"] = type
//            para["content"] = content
//        case .pushDynamic(let content, let imgs, let video, let subject_id, let gid):
//            var uid = ""
//            if let user_id = UserDefaultsManager.getString(forKey: .uid) {
//                uid = user_id
//            }
//            let tStr = RaeRequestParameterConfig.shared.getTStr()
//            let sign = RaeRequestParameterConfig.shared.encrySign()
//            para["uid"] = uid
//            para["t"] = tStr
//            para["sign"] = sign
//            para["content"] = content
//            para["imgs"] = imgs
//            para["video"] = video
//            para["subject_id"] = subject_id
//            para["gid"] = gid case .dynamicCommit(let dynamicID, let pid, let content): return urlPath + "&dongtai_id=\(dynamicID)&pid=\(pid)&content=\(content)"
            
        default: return para
        }
        return para
    }
    
}
